package com.qf.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author KING
 * @ClassName: com.qf.config.MybatisConfig
 * @Description: 该类的功能描述
 * @date: 2021/10/26 17:33
 */
@Configuration
@MapperScan("com.qf.**.mapper")
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //分页插件的对象
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        //  如果起始页小于1 返回第一页数据  如果是超过最大页数返回最后一页
        paginationInnerInterceptor.setOverflow(true);
        // 设置每页查询最大行数
        paginationInnerInterceptor.setMaxLimit(50L);
        //分页插件
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        //乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }

}